package com.yxhl.zoume.core.func.passenger.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.yxhl.zoume.R;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.data.http.model.passenger.ZMPassenger;
import com.yxhl.zoume.di.component.base.HasComponent;
import com.yxhl.zoume.di.component.usercenter.DaggerPassengerComponent;
import com.yxhl.zoume.di.component.usercenter.PassengerComponent;
import com.yxhl.zoume.di.module.usercenter.PassengerModule;

import java.io.Serializable;
import java.util.List;


public class SelectPsgersActivity extends BaseActivityWithToolBar implements HasComponent<PassengerComponent> {
    private static final String INTENT_EXTRA_SELECTED_PASSENGERS = "INTENT_EXTRA_SELECTED_PASSENGERS";
    private static final String INTENT_EXTRA_ITEM_TYPE = "INTENT_EXTRA_ITEM_TYPE";
    private static final String INTENT_EXTRA_ITEM_MULTIPLE_SELECT_TYPE = "intent_extra_item_type_additional_flag";

    PassengerComponent component;

    List<ZMPassenger> mSelectedPassengers;
    PsgerItemType mItemType;
    MultipleSelectType mMultipleSelectType;

    public static Intent getCallingIntent(Context context, List<ZMPassenger> selectedPassengers, PsgerItemType itemType) {
        Intent callingIntent = new Intent(context, SelectPsgersActivity.class);
        callingIntent.putExtra(INTENT_EXTRA_SELECTED_PASSENGERS, (Serializable) selectedPassengers);
        callingIntent.putExtra(INTENT_EXTRA_ITEM_TYPE, itemType);
        return callingIntent;
    }

    public static Intent getCallingIntent(Context context, List<ZMPassenger> selectedPassengers, PsgerItemType itemType, MultipleSelectType selectType) {
        Intent callingIntent = new Intent(context, SelectPsgersActivity.class);
        callingIntent.putExtra(INTENT_EXTRA_SELECTED_PASSENGERS, (Serializable) selectedPassengers);
        callingIntent.putExtra(INTENT_EXTRA_ITEM_TYPE, itemType);
        callingIntent.putExtra(INTENT_EXTRA_ITEM_MULTIPLE_SELECT_TYPE, selectType);
        return callingIntent;
    }

    private void handleIntent() {
        Intent intent = getIntent();
        if (null != intent) {
            Bundle bundle = intent.getExtras();
            mSelectedPassengers = (List<ZMPassenger>) bundle.getSerializable(INTENT_EXTRA_SELECTED_PASSENGERS);
            mItemType = (PsgerItemType) bundle.getSerializable(INTENT_EXTRA_ITEM_TYPE);
            mMultipleSelectType = (MultipleSelectType) bundle.getSerializable(INTENT_EXTRA_ITEM_MULTIPLE_SELECT_TYPE);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent();
        addFragment(R.id.select_passengers_container, SelectPsgersFragment.newInstance(mSelectedPassengers, mItemType, mMultipleSelectType));
    }


    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_select_passengers;
    }

    @Override
    protected void initializeInjector() {
        this.component = DaggerPassengerComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(getActivityModule())
                .passengerModule(new PassengerModule())
                .build();
    }

    @Override
    public PassengerComponent getComponent() {
        return component;
    }
}
